package com.action.basic;

import java.util.List;

import com.action.common.WEB;
import com.opensymphony.xwork2.ActionSupport;
import com.pojo.basic.SALM;
import com.service.basic.ISALMService;
import com.util.ActionLog;
import com.util.GTC;

public class SALMAction extends ActionSupport {
	
	private static final long serialVersionUID = 1L;
	private ISALMService salmService;
	private List<SALM> salms;
	private String  datas;
	
	//seter getter
	
	
	public void setSalmService(ISALMService salmService) {
		this.salmService = salmService;
	}

	public String getDatas() {
		return datas;
	}

	public void setDatas(String datas) {
		this.datas = datas;
	}

	public List<SALM> getSalms() {
		return salms;
	}

	public void setSalms(List<SALM> salms) {
		this.salms = salms;
	}
	
	//action method
	public String findAllSALM(){
		ActionLog.info(this.getClass(),"["+WEB.getClassName(this.getClass())+"]:【加載所有员工资料】");
		this.allSalmFormatExtArray(salmService.findAllSALM());
		return SUCCESS;
	}
	
	public void allSalmFormatExtArray(List<SALM> lists){
		ActionLog.info(this.getClass(),"["+WEB.getClassName(this.getClass())+"]:【员工對象轉換為JS字符串形式顯示在頁面】");
		StringBuffer sb = new StringBuffer();
		sb.append("[");
		for(SALM salm : lists){
			
			sb.append("['"+salm.getSAL_NO()+"','"+GTC.nullEmpty(salm.getNAME())+"','"+GTC.nullEmpty(salm.getENG_NAME())+"','"+GTC.nullEmpty(salm.getTEL1())+"','"+GTC.nullEmpty(salm.getTEL2())+"','"+GTC.nullEmpty(salm.getBBC())+"','"+GTC.nullEmpty(salm.getDEP()==null?"":salm.getDEP().getNAME())+"','"+GTC.nullEmpty(salm.getPOS())+"','"+GTC.nullEmpty(salm.getBTH())+"','"+GTC.nullEmpty(salm.getDUT_IN_D())+"','"+GTC.nullEmpty(salm.getDUT_OT_D())+"','"+GTC.nullEmpty(salm.getUP_SAL_NO())+"'],");
		}
		this.setDatas(sb.toString().substring(0, sb.toString().length()-1)+"]");
	}
}
